namespace Isolation.TeamFoundationServer
{
	#region #using Directives

	using System;

	using Microsoft.TeamFoundation.WorkItemTracking.Client;

	#endregion

	public class WorkItem : IWorkItem
	{
		private readonly Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem;

		internal WorkItem(Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem)
		{
			this.workItem = workItem;
		}

		#region Implementation of IWorkItem

		public object this[string index]
		{
			get
			{
				try
				{
					return this.workItem[index];
				}
				catch (ConnectionException e)
				{
					throw new TfsConnectionException(e);
				}
			}
		}

		public int Id
		{
			get
			{
				try
				{
					return this.workItem.Id;
				}
				catch (ConnectionException e)
				{
					throw new TfsConnectionException(e);
				}
			}
		}

		public string Title
		{
			get
			{
				try
				{
					return this.workItem.Title;
				}
				catch (ConnectionException e)
				{
					throw new TfsConnectionException(e);
				}
			}
		}

		public string AssignedTo
		{
			get
			{
				try
				{
					return (string) this.workItem[CoreFieldReferenceNames.AssignedTo];
				}
				catch (ConnectionException e)
				{
					throw new TfsConnectionException(e);
				}
			}
		}

		public string Type
		{
			get
			{
				try
				{
					return this.workItem.Type.Name;
				}
				catch (ConnectionException e)
				{
					throw new TfsConnectionException(e);
				}
			}
		}

		public string State
		{
			get
			{
				try
				{
					return this.workItem.State;
				}
				catch (ConnectionException e)
				{
					throw new TfsConnectionException(e);
				}
			}
		}

		public string ChangedBy
		{
			get
			{
				try
				{
					return this.workItem.ChangedBy;
				}
				catch (ConnectionException e)
				{
					throw new TfsConnectionException(e);
				}
			}
		}

		public DateTime ChangedDate
		{
			get
			{
				try
				{
					return this.workItem.ChangedDate;
				}
				catch (ConnectionException e)
				{
					throw new TfsConnectionException(e);
				}
			}
		}

		public bool HasField(string fieldName)
		{
			try
			{
				return this.workItem.Fields.Contains(fieldName);
			}
			catch (ConnectionException e)
			{
				throw new TfsConnectionException(e);
			}
		}

		#endregion

		public override int GetHashCode()
		{
			return this.workItem.GetHashCode();
		}
	}
}